package comgame.components.EquipmentComponent;

import com.almasb.fxgl.dsl.FXGL;
import comgame.entities.EquipmentEnum.LeggingType;

public class LeggingComponent extends EquipmentComponent {

    private final LeggingType leggingType;
    private String displayName;
    public LeggingComponent(LeggingType leggingType) {
        super(leggingType);
        this.leggingType = leggingType;
    }
    public int getAttack() {
        return leggingType.getAttack();
    }
    public int getDefense() {
        return leggingType.getDefense();
    }
    public int getSpeed() {
        return leggingType.getSpeed();
    }
    public double getCritRate() {
        return leggingType.getCritRate();
    }
    public String getDisplayName() {
        return displayName != null ? displayName : leggingType.getName();
    }
    @Override
    public void onAdded() {
        super.onAdded();
        System.out.println("LeggingComponent onAdded 被调用");
        
        // 只更新AttributeComponent，不直接更新Player对象
        comgame.components.AttributeComponent attr = entity.getComponent(comgame.components.AttributeComponent.class);
        if (attr != null) {
            System.out.println("装备护腿: " + leggingType.getName() + 
                " 攻击+" + leggingType.getAttack() + 
                " 防御+" + leggingType.getDefense() + 
                " 速度+" + leggingType.getSpeed() +
                " 暴击率+" + String.format("%.2f", leggingType.getCritRate() * 100) + "%");
        }
    }

    @Override
    public void onRemoved() {
        super.onRemoved();
        System.out.println("LeggingComponent onRemoved 被调用");
        // 只更新AttributeComponent，不直接更新Player对象
        comgame.components.AttributeComponent attr = entity.getComponent(comgame.components.AttributeComponent.class);
        if (attr != null) {
        }
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + 魔法抗性";
        // 添加描述
    }
}
